Getting Started with Inmetpy¶

In [32]:
import plotly.io as pio
pio.renderers.default = "plotly_mimetype+notebook"
In [33]:
import pandas as pd 
import plotly.express as px 


from inmetpy.inmet_stations import InmetStation
In [34]:
inmet = InmetStation()

stations = inmet.stations
In [35]:
stations.LATITUDE = stations.LATITUDE.astype(float)
stations.LONGITUDE = stations.LONGITUDE.astype(float)

Get details of all stations¶

In [36]:
fig = px.scatter_mapbox(stations, lat="LATITUDE", lon="LONGITUDE", hover_name="STATION_NAME", hover_data=["TP_STATION", "CD_SITUATION"],
                        color = "CD_SITUATION", 
                        zoom=3.8, height=300, 
                        color_discrete_map= {'Down': 'red',
                                             'Operative': 'green'})
                                                                  
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_layout(height=800, width=1000)
fig.update_layout(legend=dict(
    yanchor="top",
    y=0.99,
    xanchor="left",
    x=0.79
))
fig.show()
In [37]:
# Mapa com a coloração da temperatura
all_stations_data = inmet.get_all_stations()
In [38]:
all_stations_data.LAT
Out[38]:
0        -15.78944444
1        -15.78944444
2        -15.78944444
3        -15.78944444
4        -15.78944444
             ...     
14396    -19.97999999
14397    -19.97999999
14398    -19.97999999
14399    -19.97999999
14400    -19.97999999
Name: LAT, Length: 14401, dtype: object
In [39]:
all_stations_data.LAT = all_stations_data.LAT.astype(float)
all_stations_data.LONG = all_stations_data.LONG.astype(float)
In [40]:
all_stations_data.TEMP = all_stations_data.TEMP.astype(float)
In [41]:
daily_mean = all_stations_data.groupby(['STATION_NAME', 'LAT','LONG'])['TEMP'].mean().to_frame(name = 'TEMP').reset_index()
In [42]:
daily_mean.dropna(inplace=True)
In [43]:
daily_mean
Out[43]:
STATION_NAME LAT LONG TEMP
1 ACARAÚ -3.121111 -40.087222 25.962500
2 AFONSO CLAUDIO -20.104167 -41.106944 20.370833
3 AGUAS EMENDADAS -15.596491 -47.625801 19.425000
4 AIMORES -19.532778 -41.090833 25.057143
5 ALEGRE -20.750556 -41.488889 21.900000
... ... ... ... ...
592 VIÇOSA -20.762607 -42.864013 16.782609
596 ZE DOCA -3.269167 -45.651111 27.329167
598 ÁGUA CLARA -20.444444 -52.875833 24.375000
599 ÁGUAS VERMELHAS -15.751536 -41.457787 20.375000
600 ÓBIDOS -1.880833 -55.519722 27.087500

421 rows × 4 columns

In [ ]:
 
In [44]:
fig = px.scatter_mapbox(daily_mean, lat="LAT", lon="LONG", color="TEMP",
                  color_continuous_scale=px.colors.cyclical.IceFire, zoom=3.8,
                       mapbox_style = 'open-street-map')
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_layout(height=800, width=1000)
fig.show()
In [45]:
states = ['RJ']
rj_stations = inmet.search_station_by_state(states, station_type = "A")
In [46]:
rj_stations
Out[46]:
CD_OSCAR STATION_NAME FL_CAPITAL END_DATE_OPERATION CD_SITUATION TP_STATION LATITUDE CD_WSI CD_DISTRICT HEIGHT STATE INSTITUTE CD_STATION LONGITUDE START_DATE_OPERATION
23 None ANGRA DOS REIS N None Operative Automatic -22.975556 0-76-0-3300100000000555 06 6 RJ INMET A628 -44.303333 2017-08-24T21:00:00.000-03:00
41 0-2000-0-86892 ARRAIAL DO CABO N None Operative Automatic -22.975278 0-76-0-3300258000000108 06 5 RJ INMET A606 -42.021389 2006-09-21T21:00:00.000-03:00
98 0-2000-0-86854 CAMBUCI N None Operative Automatic -21.587500 0-76-0-3300902000000025 06 46 RJ INMET A604 -41.958333 2002-11-19T22:00:00.000-02:00
109 0-2000-0-86855 CAMPOS DOS GOYTACAZES N None Operative Automatic -21.714722 0-76-0-3301009000000109 06 17 RJ INMET A607 -41.343889 2006-09-24T21:00:00.000-03:00
110 0-2000-0-86890 CAMPOS DOS GOYTACAZES - SAO TOME N None Operative Automatic -22.041667 0-76-0-3301009000000382 06 7 RJ INMET A620 -41.051667 2008-06-12T21:00:00.000-03:00
125 None CARMO N None Operative Automatic -21.938745 0-76-0-3301207000000583 06 293 RJ INMET A629 -42.600936 2018-10-10T21:00:00.000-03:00
180 0-2000-0-86877 DUQUE DE CAXIAS - XEREM N None Operative Automatic -22.589722 0-76-0-3301702000000022 06 22 RJ INMET A603 -43.282222 2002-10-20T21:00:00.000-03:00
255 None ITATIAIA - AGULHAS NEGRAS N None Operative Automatic -22.373889 0-76-0-3302254000000557 06 2450 RJ INMET A635 -44.703056 2017-08-31T21:00:00.000-03:00
295 0-2000-0-86891 MACAE N None Operative Automatic -22.376111 0-76-0-3302403000000106 06 28 RJ INMET A608 -41.811944 2006-09-21T21:00:00.000-03:00
338 None NITEROI N None Operative Automatic -22.867500 0-76-0-3303302000000580 06 6 RJ INMET A627 -43.101944 2018-07-12T21:00:00.000-03:00
341 0-2000-0-86889 NOVA FRIBURGO - SALINAS None None Operative Automatic -22.334722 0-76-0-3303401000000466 06 1070 RJ INMET A624 -42.676944 2010-09-17T21:00:00.000-03:00
370 0-2000-0-86913 PARATY N None Operative Automatic -23.223611 0-76-0-3303807000000141 06 3 RJ INMET A619 -44.726944 2006-11-18T21:00:00.000-03:00
386 0-2000-0-86876 PICO DO COUTO N None Operative Automatic -22.464722 0-76-0-3303906000000121 06 1777 RJ INMET A610 -43.291389 2006-10-21T21:00:00.000-03:00
428 0-2000-0-86874 RESENDE N None Operative Automatic -22.451389 0-76-0-3304201000000114 06 438.83 RJ INMET A609 -44.445000 2006-09-28T21:00:00.000-03:00
432 None RIO CLARO N None Operative Automatic -22.653579 0-76-0-3304409000000518 06 516 RJ INMET A626 -44.040916 2016-06-02T21:00:00.000-03:00
433 0-2000-0-86887 RIO DE JANEIRO - FORTE DE COPACABANA None None Operative Automatic -22.988333 0-76-0-3304557000000187 06 25.59 RJ INMET A652 -43.190556 2007-05-17T21:00:00.000-03:00
434 None RIO DE JANEIRO - JACAREPAGUA N None Operative Automatic -22.940000 0-76-0-3304557000000553 06 20 RJ INMET A636 -43.402778 2017-08-09T21:00:00.000-03:00
435 0-2000-0-86879 RIO DE JANEIRO - VILA MILITAR N None Operative Automatic -22.861389 0-76-0-3304557000000179 06 30.43 RJ INMET A621 -43.411389 2007-04-12T21:00:00.000-03:00
436 0-2000-0-86914 RIO DE JANEIRO-MARAMBAIA N None Operative Automatic -23.050278 0-76-0-3304557000000024 06 12 RJ INMET A602 -43.595556 2002-11-07T22:00:00.000-02:00
461 None SANTA MARIA MADALENA N None Operative Automatic -21.950556 0-76-0-3304607000000584 06 517 RJ INMET A630 -42.010278 2018-10-15T21:00:00.000-03:00
503 0-2000-0-86885 SAQUAREMA - SAMPAIO CORREIA N None Operative Automatic -22.871111 0-76-0-3305505000000507 06 26 RJ INMET A667 -42.608889 2015-09-01T21:00:00.000-03:00
506 0-2000-0-86878 SEROPEDICA-ECOLOGIA AGRICOLA N None Operative Automatic -22.757778 0-76-0-3305554000000002 06 35 RJ INMET A601 -43.684722 2000-05-23T21:00:00.000-03:00
515 0-2000-0-86893 SILVA JARDIM N None Operative Automatic -22.645833 0-76-0-3305604000000505 06 19 RJ INMET A659 -42.415556 2015-08-27T21:00:00.000-03:00
531 0-2000-0-86888 TERESOPOLIS-PARQUE NACIONAL N None Operative Automatic -22.448611 0-76-0-3305802000000131 06 981 RJ INMET A618 -42.986944 2006-10-31T21:00:00.000-03:00
540 None TRES RIOS N None Operative Automatic -22.098333 0-76-0-3306008000000519 06 295 RJ INMET A625 -43.208333 2016-06-07T21:00:00.000-03:00
556 0-2000-0-86875 VALENCA N None Operative Automatic -22.358056 0-76-0-3306107000000111 06 370 RJ INMET A611 -43.695556 2006-09-26T21:00:00.000-03:00
In [47]:
stations = ['A627']
niteroi = inmet.get_data_station('2019-01-01','2020-01-01', by='day',station_id = stations)
A627
Looking for station A627...
In [48]:
niteroi.TEMP_MED.plot(x='DATE')
Out[48]:
<AxesSubplot:>
In [49]:
niteroi.columns
Out[49]:
Index(['index', 'DATE', 'AVG_RH', 'STATION_NAME', 'MIN_RH', 'TEMP_MED', 'RAIN',
       'LAT', 'TEMP_MIN', 'TEMP_MAX', 'ST', 'WSPD', 'STATION_ID', 'LONG'],
      dtype='object')
In [50]:
temp = px.line(x=niteroi.DATE,y=niteroi.TEMP_MED, labels = {'x':'Date', 'y':'°C'},
              markers='line+markers')
temp.update_layout(title="Niteroi Station Temperature")
temp.show()
In [ ]: